// 响应系统 3.0 实现分支切换

const targetMappingFieldMappingEffectFunctionSet = new WeakMap<Object, Map<String | symbol, Set<Function>>>();


let activeEffect

const proxyHandler: ProxyHandler<Object> = {
    get(target: Object, key: string | symbol, receiver: any): any {


    },
    set(target: Object, key: string | symbol, newValue: any, receiver: any): boolean {

        target[key] = newValue

        if (!activeEffect) {
            return
        }


        let fieldMappingEffectFunctionSet = targetMappingFieldMappingEffectFunctionSet.get(target);

        if (!fieldMappingEffectFunctionSet) {
            targetMappingFieldMappingEffectFunctionSet.set(target, (fieldMappingEffectFunctionSet = new Map<>()))
        }

        let effectFunctionSet = fieldMappingEffectFunctionSet.get(key);

        if (!effectFunctionSet) {
            fieldMappingEffectFunctionSet.set(key, (effectFunctionSet = new Set<Function>()))
        }

        effectFunctionSet.add(activeEffect)

        return false;
    }
}

function effect(fn: Function) {

    const effectFn = () => {
        activeEffect = fn
    }

    effectFn.effectFunctionSetArray = []

    effectFn()
}

